package com.example.dailyrecord.controller;

import com.example.dailyrecord.base.entity.ResultMsg;
import com.example.dailyrecord.entity.StatusCode;
import com.example.dailyrecord.service.EmailService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping("/email")
@Api(tags = {"邮箱服务"})
public class EmailController {
    @Resource
    EmailService emailService;

    @GetMapping("/sendCode")
    @ApiOperation("发送验证码")
    public ResultMsg sendCode(HttpServletRequest request, HttpServletResponse response) {
        StatusCode result = emailService.sendCode(request, response);
        return ResultMsg.getInstance(result);
    }

    @Scheduled(cron = "0 0 23 * * ?")
    @ApiOperation("发送提醒邮箱")
    public void sendNoteEmail() {
        emailService.sendNoteEmail();
    }
}
